<?php
class Read_circles extends CI_Model{
	
	function get_habit_data($ids, $limit = 5){
		$sql = "SELECT * FROM {$this->db->dbprefix}task_types WHERE id IN($ids) AND status = 1 LIMIT $limit";
		$result = $this->db->query($sql)->result_array();
		return $result;
	}

	function get_book_data($ids, $limit = 3){
		$sql = "SELECT * FROM {$this->db->dbprefix}books WHERE id IN($ids) AND status = 1 LIMIT $limit";
		$result = $this->db->query($sql)->result_array();
		return $result;
	}

	function get_article_data($ids, $limit = 5){
		$sql = "SELECT * FROM {$this->db->dbprefix}articles WHERE id IN($ids) AND status = 1 LIMIT $limit";
		$result = $this->db->query($sql)->result_array();
		return $result;
	}

	function get_dynamic_list($limit = 0, $offset = 10){
		$fields = "ud.id,ud.type,ud.data_id,ud.category_id,ud.stars,ud.text,ud.image,FROM_UNIXTIME(ud.add_time) AS add_time,uc.nick,uc.head_img_url";
		$sql = "SELECT SQL_CALC_FOUND_ROWS $fields FROM {$this->db->dbprefix}user_dynamics AS ud ";
		$sql .= "LEFT JOIN {$this->db->dbprefix}user_childrens AS uc ON(uc.id=ud.child_id) ";
		$sql .= "ORDER BY id DESC LIMIT $limit, $offset";
		$result = $this->db->query($sql)->result_array();
		$row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();
		return array("count" => $row_num['row_num'], "list" => $result);
	}
}